<%--
  接力页面
  User: kent
  Date: 15/10/20
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="packtag" prefix="pack" %>
<c:set var="ctx" value="${pageContext.request.contextPath }"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <pack:style>
        <src>/static/weui/css/weui.min.css</src>
        <src>/static/css/activity/style.css</src>
        <src>/static/sweetalert/sweetalert.css</src>
    </pack:style>

    <pack:script>
        <src>/static/wx/wx.js</src>
        <src>/static/zepto/zepto.min.js</src>
        <src>/static/activity/cover.js</src>
        <src>/static/sweetalert/sweetalert.min.js</src>
    </pack:script>

    <script>
        wx.config(${config});

        wx.ready(function () {
            wx.onMenuShareAppMessage({
                title: '我向房东打白条', // 分享标题
                desc: '${result.shareDesc}', // 分享描述
                link: '${shareUrl}', // 分享链接
                imgUrl: '${shareImgUrl}', // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    //afterShare();
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.onMenuShareTimeline({
                title: '我向房东打白条', // 分享标题
                link: '${shareUrl}', // 分享链接
                imgUrl: '${shareImgUrl}', // 分享图标
                success: function () {
                    //afterShare();
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.hideMenuItems({
                menuList: ["menuItem:copyUrl"]
            });
        });
    </script>
    <title>接力</title>
</head>
<body ontouchstart>
<div class="wrapper">
    <div class="bg-img"><img src="<c:url value="/static/img/activity/tittle.jpg"/>"></div>

    <article class="weui_article" style="color: #ffffff">
        <p>亲:</p>
        <c:choose>
            <c:when test="${result.isRank}">
                <p id="descContent">我是${result.my.nickName},我现在正在参加租+『我向房东打白条』活动,已经有${result.my.count}位亲友帮我打了${result.bond.amount}元白条,快来帮我接力吧,么么哒!</p>
            </c:when>
            <c:otherwise>
                <p id="descContent">我是${result.my.nickName},我现在正在参加租+『我向房东打白条』活动,已经有${result.my.count}位亲友帮我接力了,还差${10-result.my.count}位亲友,我就可以领取『房租抵用券』了,快来帮我接力吧!么么哒!</p>
            </c:otherwise>
        </c:choose>
    </article>

    <form>
        <div class="weui_cells weui_cells_form" style="margin: 0 15px">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <input id="nickName" name="nickName" required class="weui_input" type="text"
                           placeholder="请输入您的姓名或昵称"/>
                </div>
                <div class="weui_cell_ft">
                    <i class="weui_icon_warn"></i>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">
                    <input id="mobile" name="mobile" required class="weui_input" type="tel" placeholder="请输入您的手机号"
                           data-phone/>
                </div>
                <div class="weui_cell_ft">
                    <i class="weui_icon_warn"></i>
                </div>
            </div>
        </div>

        <input id="fromOpenid" name="fromOpenid" type="hidden" value="${fromOpenId}"/>
        <input id="openid" name="openid" type="hidden" value="${openId}"/>
    </form>

    <div style="margin: 15px;overflow: hidden">
        <a href="javascript:void(0);" id="relayBtn" style="width: 45%;" class="pull-left weui_btn btn-warning">为TA接力</a>
        <a href="javascript:void(0);" id="joinBtn" style="width: 45%;margin-top: 0"
           class="pull-right weui_btn btn-warning">我也来参加</a>
    </div>


    <div class="rule">
        <img src="<c:url value="/static/img/activity/main.png"/>">
    </div>

    <%--<div id="relayTip" class="cover">
        <div style="position: absolute; top: 1rem;right: 1.5rem">
            <img style="width: 2rem" src="${ctx}/static/img/activity/guide.png">
        </div>
        <div style="text-align: center;margin-top: 5em">
            <h2 style="color: #B9B9B9">快转发至朋友圈让好友看到您在为TA接力吧!若未转发视为接力失败.</h2>
        </div>
    </div>--%>

</div>
</body>
<script type="text/javascript" src="${ctx}/static/validator/validator.js"></script>
<script>

    $(function () {
        $("#joinBtn").on("click", joinHandler);
        $("#relayBtn").on("click", relayHandler);
        validator.validate();
    });

    //参加活动
    function joinHandler() {
        location.href = '${joinUrl}';
    }

    //接力
    function relayHandler() {

        if (!validator.success()){
            return;
        }

        var $form = $("form");
        $.post('/rent/activity/relay',
                $form.serialize(),
                function (data) {
                    if (data.resultCode == '1000') {
                        swal("提示", "接力成功", "success");
                        //更新文字说明
                        updateDesc(data.resultData);
                    } else {
                        swal("提示", data.resultMsg, "error");
                    }
                });
    }

    //分享成功
/*    function afterShare() {
        $.post('/rent/activity/afterShare',
                {fromOpenid: '${fromOpenId}', openid: '${openId}'},
                function (data) {
                    if (data.resultCode == '1000') {
                        swal("提示", "接力成功", "success");
                        //更新文字说明
                        updateDesc(data.resultData);
                    } else {
                        if (data.resultCode != '2004') {
                            swal("提示", data.resultMsg, "error");
                        }
                    }
                });

        $("#relayTip").hide();
    }*/

    function updateDesc(result){
        var $descContent = $("#descContent");
        var text = '';
        if(result.isRank){
            text = '我是'+result.my.nickName+',我现在正在参加租+『我向房东打白条』活动,已经有'+result.my.count+'位亲友帮我打了'+result.bond.amount+'元白条,快来帮我接力吧,么么哒!';
        }else{
            text = '我是'+result.my.nickName+',我现在正在参加租+『我向房东打白条』活动,已经有'+result.my.count+'位亲友帮我接力了,还差'+(10-result.my.count)+'位亲友,我就可以领取『房租抵用券』了,快来帮我接力吧!么么哒!';
        }
        $descContent.text(text);
    }
</script>
</html>
